﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Projekt
{
    public partial class billArchive : Form
    {
        public billArchive()
        {
            InitializeComponent();
        }

        private void nirNrInput_TextChanged(object sender, EventArgs e)
        {
            try
            {
               nirList.Items.Clear();
                Bill fakt = Bill.Instance;
                DataTable dt = fakt.getBillList(nirNrTextBox.Text, supplierNameTextBox.Text, BillDateTextBox.Text, billNrTextBox.Text);
                foreach (DataRow rows in dt.Rows)
                {
                    ListViewItem it = new ListViewItem(rows["NirNr"].ToString());
                    it.SubItems.Add(rows["CNev"].ToString());
                    it.SubItems.Add(rows["NDatum"].ToString());
                    it.SubItems.Add(rows["NSorszam"].ToString());

                    nirList.Items.Add(it);
                }
                fakt = Bill.disposeInstance;
            }
            catch (Exception es) { MessageBox.Show(es.ToString()); }
        }

        private void billArchive_Load(object sender, EventArgs e)
        {
            try
            {
                BillDateTextBox.Text = String.Format("{0:s}", DateTime.Now).Remove(10);
            }
            catch (Exception es) { MessageBox.Show(es.ToString()); }    
    
        }

        private void editMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem it = nirList.FocusedItem;
            if (it != null)
            {
                introduceBill kl = new introduceBill(it.SubItems[0].Text);
                if (kl.accesible()) kl.Show();
            }
        }

        private void deleteMenuItem_Click(object sender, EventArgs e)
        {
            ListViewItem it = nirList.FocusedItem;
            Bill fakt = Bill.Instance;
            fakt.deleteBill(it.SubItems[0].Text);
            nirList.Items.Remove(it);
            fakt = Bill.disposeInstance;
            
        }

        private void deleteOldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form kl = new deleteOldNir();
            kl.Show();
        }
    }
}
